 package munyOrderWeb;

import java.io.IOException;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;

import javax.servlet.RequestDispatcher;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

public class SystemServlet extends HttpServlet
{
	protected void doGet(HttpServletRequest req,
						 HttpServletResponse resp)
			throws ServletException, IOException
	{
		String zipcode = req.getParameter("category_no");
		String town = req.getParameter("town");
		Connection con = null;

		try {
			con = DB_maneger.getConnection();

			String sql = "select * from tables where tables";

			PreparedStatement ps = con.prepareStatement(sql);

			ps.setString(1,"%" + category_no + "%");
			ps.setString(2,"%" + town + "%");

			ResultSet rs = ps.executeQuery();

			ArrayList<Change_Bean> list = new ArrayList<Change_Bean>();

			Change_Bean change_bean = null;
			while ( rs.next() )
			{
				change_bean = new Change_Bean();
				change_bean.setTable_no(rs.getString("table_no"));
				change_bean.setTable_name(rs.getString("table_name"));
				change_bean.setTable_seats(rs.getString("table_seats"));


				change_bean.setCategory_no(rs.getString("category_no"));
				change_bean.setCategory_name(rs.getString("category_name"));


				change_bean.setMenu_no(rs.getString("menu_no"));
				change_bean.setMenu_name(rs.getString("menu_name"));
				change_bean.setMenu_price(rs.getString("menu_price"));
				change_bean.setOrder_no(rs.getString("order_no"));
				change_bean.setOrder_count(rs.getString("order_count"));
				change_bean.setOrder_delivery(rs.getString("order_delivery"));
				change_bean.setCustomer_no(rs.getString("customer_no"));
				change_bean.setCustomer_total(rs.getString("customer_total"));
				change_bean.setCustomer_person(rs.getString("customer_person"));
				change_bean.setCustomer_member(rs.getString("customer_member"));
				change_bean.setOrder_date(rs.getString("order_date"));

				list.add(change_bean);
			}
			req.setAttribute("list", list);

			RequestDispatcher dispatcher = req.getRequestDispatcher("Result.jsp");
			dispatcher.forward(req, resp);
		}

		catch (SQLException e)
		{
			e.printStackTrace();
		}
		finally
		{
			try
			{
				con.close();
			}
			catch (SQLException e)
			{
				e.printStackTrace();
			}
		}
	}
}